//
//  Person.m
//  往沙盒中存数据和取数据Demo
//
//  Created by 向祖华 on 16/4/1.
//  Copyright © 2016年 向祖华. All rights reserved.
//

#import "Person.h"

@implementation Person

#pragma mark -- 归档与反归档
//实现两个代理方法
-(void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.name forKey:@"name"];
    [aCoder encodeInteger:self.age forKey:@"age"];
    NSData *imageData = UIImagePNGRepresentation(self.image);
    [aCoder encodeObject:imageData forKey:@"image"];
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    self = [super init];
    if (self) {
        self.name = [aDecoder decodeObjectForKey:@"name"];
        self.age = [aDecoder decodeIntegerForKey:@"age"];
        self.image =[UIImage imageWithData:[aDecoder decodeObjectForKey:@"image"]];
    }
    return self;
}

-(NSString *)description{
    return [NSString stringWithFormat:@"name = %@,age = %ld,image = %@",self.name,self.age,self.image];
}


@end
